const Subscription = require('egg').Subscription;
const dayjs = require('dayjs');

class TaskMorning extends Subscription {
  // 通过 schedule 属性来设置定时任务的执行间隔等配置
  static get schedule() {
    return {
      cron: '0 1 7 * * ?',
      type: 'worker',
      env: ['pachong']
    };
  }

  async subscribe() {
    // 生成懂球帝早报
    const dongqiuzi_zaobao = await this.ctx.service.crawlerSvc.dongqiudizaobao();
    dongqiuzi_zaobao.pic = 'https://taosha01-1253585015.cos.ap-shanghai.myqcloud.com/typora/dongqiudi-jpg.jpg';
    let result = await this.ctx.service.topicSvc.importTopics([dongqiuzi_zaobao]);
    this.logger.info(`dongqiudizaobao ready ${dongqiuzi_zaobao.length} success ${result}`);
  }
}

module.exports = TaskMorning;
